package com.sanchunhui.psc.presenter

import com.sanchunhui.psc.common.BaseApplication
import com.sanchunhui.psc.data.dao.PSCOpenHelper
import com.sanchunhui.psc.data.protocol.UserInfo
import com.sanchunhui.psc.ui.activity.SplashActivity

/**
 * @Author zyx
 * @Date 2021/4/19-14:10
 * @Dscribe
 */

class SplashPresenter(val splashActivity: SplashActivity) {

    fun isLoggedIn(): Boolean  {

        // 查询最后一次登录的用户，免登录
        val pscOpenHelper = PSCOpenHelper(splashActivity)
        val userDao = pscOpenHelper.getDao(UserInfo::class.java)
//        var user = userDao.queryBuilder().queryForFirst()
        val userList: List<UserInfo> = userDao.queryForAll()
        var user : UserInfo? = null
        if (userList.size > 0) {
            user = userList.last()
        }
        if (user != null) {
            BaseApplication.mUser = user
            if (user.loginId == -1) {
                return false // 未登录返回false
            } else {
                return true // 已登录返回true
            }
        } else {
            return false // 未登录返回false
        }

    }
}